Skip to content

Streaming dicomChunkImage fixes#789

Merged
PaulHax merged 6 commits intoKitware:mainfrom
PaulHax:streaming-onchunk-fix
Sep 24, 2025
Merged

Streaming dicomChunkImage fixes#789
PaulHax merged 6 commits intoKitware:mainfrom
PaulHax:streaming-onchunk-fix

Conversation

@PaulHax
Copy link
Copy Markdown
Collaborator

@PaulHax PaulHax commented Sep 19, 2025

  • Fix out-of-bounds writes to 3D image in DICOM series when loading chunks but expecting a 1 chunk image.
  • Fix DICOM streaming chunk error handling to surface errors to user notifications
  • Improve MIME type detection using Content-Type headers for DICOM and JSON files
  • Add validation for unsupported multiframe DICOM volumes

…out-of-bounds error

When loading remote DICOM files via manifest.json, chunks arrive incrementally
due to parallel asynchronous processing in importDataSources. This creates a
race condition where:

1. Initial chunks (e.g., 1-50) arrive and image is allocated for 50 slices
2. These chunks start loading their data
3. Additional chunks (51-100) arrive with some already having loaded data
4. Without fix: processNewChunks() attempts to write data at positions 51-100
   into an array only allocated for 50 slices, causing "offset is out of bounds"
5. With fix: reallocateImage() runs first, expanding the array to accommodate
   all chunks before any data is written

The fix ensures proper ordering:
- Move reallocateImage() call before processNewChunks()
- Fix index lookup in processNewChunks() to use actual chunk position
  instead of filtered array index

This prevents RangeError when chunks arrive in multiple batches with
pre-loaded data from parallel fetching.
…umberOfFrames=1

Fixed buffer overflow when loading DICOM series where each file has NumberOfFrames=1.
The issue occurred when the code incorrectly used NumberOfFrames (1) instead of
the actual chunk count for memory allocation, causing an offset out of bounds error
when loading subsequent slices.

Now correctly uses sortedChunks.length when multiple chunks are present, regardless
of individual NumberOfFrames values. Also fixed z-spacing calculation to use the
allocated slice count.
Trust server-provided Content-Type for JSON, DICOM, ZIP, and GZIP
files instead of always using magic byte detection.

Fixes manifest loading from URLs without .json extension.
@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 19, 2025

Deploy Preview for volview-dev ready!

Name Link
🔨 Latest commit 0367026
🔍 Latest deploy log https://app.netlify.com/projects/volview-dev/deploys/68d3ebab3c673200080d0188
😎 Deploy Preview https://deploy-preview-789--volview-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@PaulHax PaulHax force-pushed the streaming-onchunk-fix branch 3 times, most recently from c27bdc7 to 8333b04 Compare September 22, 2025 20:21
@PaulHax PaulHax changed the title Streaming onchunk fix Streaming dicomChunkImage fixes Sep 22, 2025
@PaulHax PaulHax force-pushed the streaming-onchunk-fix branch from 8333b04 to 0367026 Compare September 24, 2025 13:01
@PaulHax PaulHax added this pull request to the merge queue Sep 24, 2025
Merged via the queue into Kitware:main with commit 83564b8 Sep 24, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant